﻿using PBO.Data;
using PBO.Data.SQLite;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace PBO.Game.BattleLog
{
    internal static class LogHelper
    {
        public static IEnumerable<string> ParserText(params object[] items)
        {
            foreach (var item in items)
            {
                yield return ParserText(item);
            }
        }

        public static string ParserText(object item)
        {
            if (item.GetType() == typeof(string))
            {
                return (string)item;
            }
            else if (item.GetType() == typeof(Trait))
            {
                return GameService.GetAbility((Trait)item).Name;
            }
            else if (item.GetType() == typeof(Item))
            {
                return GameService.GetItem((Item)item).Name;
            }
            else if (item.GetType() == typeof(BattleType))
            {
                var type = (BattleType)item;
                return (string)SQLiteHelper.GetSingle("select name from pbo_type where id=" + (int)type);
            }
            else if (item.GetType() == typeof(StatType))
            {
                var type = (StatType)item;
                return (string)SQLiteHelper.GetSingle("select name from pbo_stats where id=" + (int)type);
            }
            else
            {
                return item.ToString();
            }
        }

        public static string BuildLog(string key, params object[] items)
        {
            //string log;
            string msg = SQLiteHelper.GetMsg(key);
            if (items == null || items.Length == 0 || !msg.Contains('{')) return msg;
            var array = ParserText(items).ToArray();
            return string.Format(msg, array);
        }

        public static string BuildLog(int id, params object[] items)
        {
            var msg = SQLiteHelper.GetMsg(id);
            if (items == null || items.Length == 0) return msg;
            return string.Format(msg, ParserText(items));
        }
    }
}
